import { createRouter, createWebHistory } from "vue-router";
import Login from "@/views/Login.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/login",
      name: "login",
      component: Login,
    },
    {
      path: "/signup",
      name: "signup",
      // 懒加载
      component: () => import("../views/Signup.vue"),
    },
    // 查看具体的博客占满整个页面，不在原有的框架中显示，所以需要单独写
    {
      path: "/index/article/detail/:articleId(\\d+)",
      component: () => import("../components/articles/DetailArticle.vue"),
    },
    {
      path: "/index",
      name: "index",
      // 懒加载
      component: () => import("../views/Index.vue"),
      children: [
        {
          path: "article",
          name: "article",
          children: [
            {
              path: "all",
              component: () => import("../components/articles/AllArticle.vue"),
            },
            {
              path: "myArticle",
              component: () => import("../components/articles/MyArticle.vue"),
            },
            {
              path: "deleted",
              component: () => import("../components/articles/Deleted.vue"),
            },
            {
              // 新增和修改共用页面，只不过新增时传入的博客ID为0，对应页面会判断
              // 为了防止正则表达式不支持负号，这里使用0表示新增
              path: "handle/:articleId(\\d+)",
              component: () => import("../components/articles/NewArticle.vue"),
            },
          ],
        },
        {
          path: "user",
          name: "user",
          children: [
            {
              path: "like",
              component: () => import("../components/user/Like.vue"),
            },
            {
              path: "collect",
              component: () => import("../components/user/Collect.vue"),
            },
          ],
        },
        {
          path: "comment",
          name: "comment",
          children: [
            {
              path: "myComment",
              component: () => import("../components/comments/MyComment.vue"),
            },
            {
              path: "response",
              component: () => import("../components/comments/Response.vue"),
            },
          ],
        },
      ],
    },
  ],
});

export default router;
